package com.xxx.modules.controller;;
import com.xxx.modules.service.ProductService;
import com.xxx.modules.entity.Product;
import com.xxx.modules.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import com.github.pagehelper.PageInfo;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.xxx.modules.utils.Result;
import com.xxx.modules.utils.ResultUtil;
import com.xxx.modules.utils.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * 车辆
 *
 * @author Mark sunlightcs@gmail.com
 * @since 1.0.0 2024-03-30
 */
@RestController
@RequestMapping("/common/product")
@Api(tags="车辆")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
    *  获取所有车辆
    * @param pageNum
    * @param pageSize
    * @param product
    * @return
    */

    @GetMapping("/getProductList")
    @ApiOperation("获取所有车辆")
    public Result getProductList(Product product, @RequestParam(value="pageNum",defaultValue = "1") Integer pageNum,
                                      @RequestParam(value="pageSize",defaultValue = "10") Integer pageSize){
        return productService.selectProductList(product,pageNum,pageSize);
    }


    @GetMapping("/getProductInfo")
    @ApiOperation("根据id获取单个车辆")
    public Result getProductInfo(Integer id){
        return productService.selectProductInfo(id);
    }

    /**
    * 保存车辆
    * @param product
    * @return
    */
    @PostMapping("/saveProductInfo")
    @ApiOperation("保存车辆")
    public Result saveProductInfo(@RequestBody Product product){
        return productService.saveProductInfo(product);
    }


    /**
     * 更新车辆
     * @param product
     * @return
     */

    @PutMapping("/updateProductInfo")
    @ApiOperation("更新车辆")
    public Result updateProductInfo(@RequestBody Product product){
        return productService.updateProductInfo(product);
    }

    /**
     * 根据id删除车辆
     * @param id
     * @return
     */
    @DeleteMapping("/delProductInfo")
    @ApiOperation("根据id删除车辆")
    public Result delProductInfo(Integer id){
        return productService.delProductInfo(id);
    }

    /**
     * 根据id集合批量删除车辆
     * @param idList
     * @return
     */
    @DeleteMapping("/delBatchProductInfo")
    @ApiOperation("根据id集合批量删除车辆")
    public Result delBatchProductInfo(String idList){
        return productService.delBatchProductInfo(idList);
    }








    @PostMapping("/createProductData")
    public Result createProductData(){

        List<String> imageList = new ArrayList<>();
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-10-25//242357c9-08c4-4c4f-854d-67de9b271dbe_u=1996284881,1109846881&fm=253&fmt=auto&app=138&f=JPEG.webp");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-10-30//0d09b8e2-e66d-4231-8d35-5c4552a48f2a_2dd8fe9b59774c7ca160bb2d5741c763.jpg");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-11-02//d5f5276d-07bb-435c-8b83-6673fed5f22d_Snipaste_2023-03-13_19-49-26.png");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2022-12-13//22400dd3-cc8e-4477-823b-b3fb698ef9d5_25.png");
        imageList.add("http://yjy-xiaotuxian-dev.oss-cn-beijing.aliyuncs.com/picture/2021-04-05/7f483771-6831-4a7a-abdb-2625acb755f3.png");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-10-30//0d09b8e2-e66d-4231-8d35-5c4552a48f2a_2dd8fe9b59774c7ca160bb2d5741c763.jpg");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-11-02//d5f5276d-07bb-435c-8b83-6673fed5f22d_Snipaste_2023-03-13_19-49-26.png");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-10-25//5aeb86e4-5c96-433a-8180-2ef50443dd5c_d0176b163973961ed01818d04ee94a06 (1).png");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2023-10-25//7f50ce5d-04ab-4db6-88a5-c721e0256256_7f6a7b20-7902-4b43-b9c5-f33151ef1334.jpg");
        imageList.add("https://gulimall-psw.oss-cn-hangzhou.aliyuncs.com/2021-05-04//0bed6c30-d19f-4771-8fcd-7de722195643_2016121809101738-480x300.jpg");
        for (int i=1;i<11;i++) {
            Product product = new Product();
            product.setCreateTime(TimeUtil.getCurrentTime());
            product.setUpdateTime(TimeUtil.getCurrentTime());
            product.setCarNumber("车牌号"+i);

            product.setBrandId(i);

            product.setCategoryId(i);

            product.setColor("颜色"+i);

            product.setPrice((double)(i));

            product.setSortId(i);

            product.setImageUrl( imageList.get(i-1) );

            product.setIsBanner(1);

            product.setStatus(1);

            productService.saveProductInfo(product);
        }
        return ResultUtil.success(1,"生成成功",null);
    }


}